define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'cost.budget_detail/index',
        add_url: 'cost.budget_detail/add',
        edit_url: 'cost.budget_detail/edit',
        delete_url: 'cost.budget_detail/delete',
        export_url: 'cost.budget_detail/export',
        download_tpl_url: 'cost.budget_detail/downloadTpl',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar:['refresh', 'add', 'delete','download_tpl','upload'],
                cols: [[
                    {type: "checkbox"},
                    {field: 'budget_time', minWidth: 100, title: '月份',search:false,templet: ea.table.date_to_month},
                    {field: 'time', minWidth: 120, title: '日期',search:'range',templet: ea.table.date_to_time},
                    {field: 'company.company_name', minWidth: 120, title: '城市划分'},
                    {field: 'classifys.title', minWidth: 150, title: '一级分类',templet: ea.table.string_null},
                    {field: 'classify.title', minWidth: 180, title: '二级分类',templet: ea.table.string_null},
                    {field: 'budget_name', minWidth: 120, title: '物品名称'},
                    {field: 'budget_price', minWidth: 120, title: '预算价格',searchOp:"="},
                    {field: 'budget_person', minWidth: 80, title: '负责人',search:true},
                    {width: 150,title: '操作', templet: ea.table.tool}
                ]],
            });
            var upload = layui.upload;
            upload.render({
                elem: '#upload_file'
                ,url: 'uploadFile'
                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                    layer.load(); //上传loading
                }
                ,done: function(res, index, upload){ //上传后的回调
                    ea.msg.success(res.msg)
                    layer.closeAll('loading'); //关闭loading
                    window.location.reload(); //刷新当前页面.
                }
                ,accept: 'file' //允许上传的文件类型
                ,exts:'xls|xlsx'
                ,error: function(){
                    ea.msg.error(res.msg)
                    layer.closeAll('loading'); //关闭loading
                }
            })
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        download_tpl_url: function () {
            ea.listen();
        },
    };
    return Controller;
});